package com.beeasy.tools.bean.mapper;

import com.beeasy.tools.bean.AbstractMapper;
import com.beeasy.tools.bean.objects.dos.Role;
import lombok.Data;

import java.util.*;
import java.util.stream.Collectors;

import static com.beeasy.tools.bean.BeanUtil.cast;

public class RoleNameMapper extends AbstractMapper<RoleNameMapper.RoleNameMapperParam> {

    private static Map<String, Role> roleMaps = new HashMap<>();
    static {
        roleMaps.put("1", new Role().setId("1").setName("admin"));
        roleMaps.put("2", new Role().setId("2").setName("yang"));
        roleMaps.put("3", new Role().setId("3").setName("qiang"));
    }

    @Override
    public Object to(Object src, String key, RoleNameMapperParam params) {
        List<String> ids = getValue(src, params.getKey());
        List<String> list = ids.stream()
                .map(id -> {
                    return roleMaps.get(id);
                })
                .filter(Objects::nonNull)
                .map(Role::getName)
                .collect(Collectors.toList());
        return list;
    }

    @Data
    public static class RoleNameMapperParam {
        String key;
    }
}
